#!/bin/bash 
set -e


TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage4}
SRC=${SRC:-/sources}

name=curl
version=7.75.0

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-$version.tar.xz -C $TMP

{ time \
   {

    cd $TMP/$name-$version
    
	grep -rl '#!.*python$' | xargs sed -i '1s/python/&3/'

	./configure --prefix=/usr                           \
	            --disable-static                        \
	            --enable-threaded-resolver              \
	            --with-ca-path=/etc/ssl/certs
	make

	make install

	rm -rf docs/examples/.deps &&

	find docs \( -name Makefile\* -o -name \*.1 -o -name \*.3 \) -exec rm {} \;

	install -v -d -m755 /usr/share/doc/$name-$version
	cp -v -R docs/*     /usr/share/doc/$name-$version

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
